/*****FIGURE A.III: VALIDATION OF PREDICTED RACE COUNTS****/

use ../data/main.dta, clear
local labsize = "medlarge"
local tsize = "large"

foreach r in white {
gen dvote_`r' = vote_`r' - vote_`r'_validate

sum dvote_`r' if treat, d
local m1 = r(mean)
local m1_round = round(`m1', .001)

sum dvote_`r' if !treat, d
local m2 = r(mean)
local m2_round = round(`m2', .001)

//censor histograms at -/+50 (uncensored means reported)
replace dvote_`r' = -50 if dvote_`r'<-50
replace dvote_`r' = 50 if dvote_`r'>50 & dvote_`r'<.

histogram dvote_`r' if treat, ///
text(.01 25 "mean = `m1_round'", size(medlarge) place(e)) ///
color(gs8%50) width(2.5) ///
xlabel(-50(25)50, labsize(`labsize')) xscale(range(-50 50)) ///
ylabel(0(.10).20, grid labsize(`labsize')) yscale(range(0 .21)) ///
xtitle("Error", size(`tsize')) ///
ytitle("Density", size(`tsize')) ///
plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
graph export "../output/figA3_`r'_treat.png", replace
graph export "../output/figA3_`r'_treat.eps", replace as(eps)


histogram dvote_`r' if !treat, ///
text(.01 25 "mean = `m2_round'", size(medlarge) place(e)) ///
color(gs8%50) width(2.5) ///
xlabel(-50(25)50, labsize(`labsize')) xscale(range(-50 50)) ///
ylabel(0(.10).20, grid labsize(`labsize'))  yscale(range(0 .21)) ///
xtitle("Error", size(`tsize')) ///
ytitle("Density", size(`tsize')) ///
plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
graph export "../output/figA3_`r'_ctrl.png", replace
graph export "../output/figA3_`r'_ctrl.eps", replace as(eps)

}

foreach r in black {
gen dvote_`r' = vote_`r' - vote_`r'_validate

sum dvote_`r' if treat, d
local m1 = r(mean)
local m1_round = round(`m1', .001)

sum dvote_`r' if !treat, d
local m2 = r(mean)
local m2_round = round(`m2', .001)

//censor histograms at -/+50 (uncensored means reported)
replace dvote_`r' = -50 if dvote_`r'<-50
replace dvote_`r' = 50 if dvote_`r'>50 & dvote_`r'<.

histogram dvote_`r' if treat, ///
text(.01 25 "mean = `m1_round'", size(medlarge) place(e)) ///
color(gs8%50) width(2.5) ///
xlabel(-50(25)50, labsize(`labsize')) xscale(range(-50 50)) ///
ylabel(0(.10).20, grid labsize(`labsize')) yscale(range(0 .21)) ///
xtitle("Error", size(`tsize')) ///
ytitle("Density", size(`tsize')) ///
plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
graph export "../output/figA3_`r'_treat.png", replace
graph export "../output/figA3_`r'_treat.eps", replace as(eps)


histogram dvote_`r' if !treat, ///
text(.02 25 "mean = `m2_round'", size(medlarge) place(e)) ///
color(gs8%50) width(2.5) ///
xlabel(-50(25)50, labsize(`labsize')) xscale(range(-50 50)) ///
ylabel(0(.20).40, grid labsize(`labsize'))  yscale(range(0 .42)) ///
xtitle("Error", size(`tsize')) ///
ytitle("Density", size(`tsize')) ///
plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
graph export "../output/figA3_`r'_ctrl.png", replace
graph export "../output/figA3_`r'_ctrl.eps", replace as(eps)

}

